package com.wm.eduService.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wm.commonutils.R;
import com.wm.eduService.entity.EduCourse;
import com.wm.eduService.entity.EduTeacher;
import com.wm.eduService.service.EduCourseService;
import com.wm.eduService.service.EduTeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: sshdg
 * @Date: 2020/10/7 14:45
 */
@Api(tags = "首页数据管理")
//@CrossOrigin
@RestController
@RequestMapping("/eduService/indexFront")
public class IndexFrontController {

    @Autowired
    EduCourseService courseService;
    @Autowired
    EduTeacherService teacherService;

    /**
     * 查询前8条热门课程  查询前4名讲师
     * @return
     */
    @GetMapping("/index")
    @ApiOperation("首页数据查询")
    public R index(){
        //查询前8条热门课程
        LambdaQueryWrapper<EduCourse> courseQuery = new LambdaQueryWrapper<>();
        courseQuery.orderByDesc(EduCourse::getGmtModified);
        courseQuery.last("limit 8");

        List<EduCourse> courseList = courseService.list(courseQuery);

        //查询前4条名师
        LambdaQueryWrapper<EduTeacher> teacherQuery = new LambdaQueryWrapper<>();
        teacherQuery.orderByDesc(EduTeacher::getGmtModified);
        teacherQuery.last("limit 4");

        List<EduTeacher> teacherList = teacherService.list(teacherQuery);

        return R.ok().data("courses",courseList).data("teachers",teacherList);

    }
}
